package com.zuihai.app.app;

import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.support.multidex.MultiDex;

import com.blankj.utilcode.util.Utils;
import com.jess.arms.base.BaseApplication;
import com.tencent.bugly.crashreport.CrashReport;

import com.tencent.stat.StatConfig;
import com.tencent.stat.StatService;


import org.litepal.LitePal;

import java.util.Iterator;
import java.util.List;


/**
 * Created by Administrator on 2017/5/12 0012.
 */

public class MyApplication extends BaseApplication {
    private static Context context;

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
        init();
    }

    private void init() {
        CrashReport.initCrashReport(getApplicationContext(), "e5cacfdde2", true);
        //初始化数据库工具
        LitePal.initialize(context);
        //初始化UtilCode
        Utils.init(context);
        // [可选]设置是否打开debug输出，上线时请关闭，Logcat标签为"MtaSDK"
        StatConfig.setDebugEnable(false);
        // 基础统计API
        StatService.registerActivityLifecycleCallbacks(this);
    }

    private String getAppName(int pID) {
        String processName = null;
        ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
        List l = am.getRunningAppProcesses();
        Iterator i = l.iterator();
        PackageManager pm = this.getPackageManager();
        while (i.hasNext()) {
            ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next());
            try {
                if (info.pid == pID) {
                    processName = info.processName;
                    return processName;
                }
            } catch (Exception e) {
                // Log.d("Process", "Error>> :"+ e.toString());
            }
        }
        return processName;
    }

    public static Context getContext() {
        return context;
    }


}
